def cgi_escape (s, quote=None):
	"""Replace special characters '&', '<' and '>' by SGML entities."""
	s = s.replace("&", "&amp;") # Must be done first!
	s = s.replace("<", "&lt;")
	s = s.replace(">", "&gt;",)
	if quote:
		s = s.replace('"', "&quot;")
	return s
